package com.sgzn.sgpay.enums;

import com.sgzn.sgpay.util.EnumUtil;
import lombok.Getter;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;

/**
 * 订单状态
 * @author huangsenguang
 */
public enum OrderStateEnum {

    SM_INI("SM_INI","预生成"),
    SM_AFT("SM_AFT","预付后(处理中)"),
    SM_SUC("SM_SUC","订单成功"),
    SM_FAIL("SM_FAIL","订单失败"),
    ;

    @Getter
    private String code;

    @Getter
    private String desc;

    private OrderStateEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private static final Map<String, String> map = new HashMap<String, String>();

    static{
        for(OrderStateEnum single : OrderStateEnum.values()){
            map.put(single.code, single.desc);
        }
    }

    public static OrderStateEnum resolve(String code) {
        return EnumUtil.resolveFromCode(code, OrderStateEnum.class);
    }

    /**
     * 解释翻译
     * @param code
     * @return
     */
    public static final String explain(String code) {
        return map.get(code);
    }
}

